package Factory;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

import Componand.Ireader;
import Componand.XmiReader.XmiReader;
import Factory.interfaces.IreaderFactory;
import Model.interfaces.Idiagrame;

public class ReaderFactory implements  IreaderFactory{
		Ireader reader;
	@Override
	public Idiagrame create(File p) {
		File f=p;
		if(getExtension(f).equals("xmi")){
			reader=new XmiReader();
			reader.Read(f);
			reader.convert();
		}
		return reader.convert();
		
		
		
		
	}

	
	public  String getExtension(File f)
	{
	String ext = null;
	String s = f.getName();
	int i = s.lastIndexOf('.');

	if (i > 0 && i < s.length() - 1)
	ext = s.substring(i+1).toLowerCase();

	if(ext == null)
	return "not found";
	return ext;
	}
}
